/**
 * 轮滑进销存储管理初始化
 */
var Skate = {
    id: "SkateTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Skate.initColumn = function () {
    return [
            {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '名称', field: 'name', visible: true, align: 'center', valign: 'middle'},
            {title: '码数', field: 'type', visible: true, align: 'center', valign: 'middle'},
            {title: '级别', field: 'level', visible: true, align: 'center', valign: 'middle'},
            {title: '颜色', field: 'color', visible: true, align: 'center', valign: 'middle'},
            {title: '数量（双）', field: 'number', visible: true, align: 'center', valign: 'middle'},
            {title: '单价（元）', field: 'price', visible: true, align: 'center', valign: 'middle'},
            {title: '合计（元）', field: 'sum', visible: true, align: 'center', valign: 'middle'},
            {title: '创建时间', field: 'createTime', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
Skate.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Skate.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加轮滑进销存储
 */
Skate.openAddSkate = function () {
    var index = layer.open({
        type: 2,
        title: '添加轮滑进销存储',
        area: ['1000px', '650px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/skate/skate_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看轮滑进销存储详情
 */
Skate.openSkateDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '轮滑进销存储详情',
            area: ['1000px', '650px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/skate/skate_update/' + Skate.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除轮滑进销存储
 */
Skate.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/skate/delete?", function (data) {
            Feng.success("删除成功!");
            Skate.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("skateId",this.seItem.id);
        ajax.start();
    }
};


/**
 * 导入轮滑进销存储
 */
Skate.import = function () {
	var index = layer.open({
		type:2,
		title:'导入',
		area:['800px','420px'],
		fix:false,
		maxmin:true,
		content:Feng.ctxPath + '/base/jumpToImportUI'
	});
	this.layerIndex = index;
};



/**
 * 导出轮滑进销存储
 */
Skate.export = function () {
	var ajax = new $ax(Feng.ctxPath + "/skate/export?name="+$("#name").val()+"&type="+$("#type").val()+"&color="+$("#color").val()+"&level="+$("#level").val(), function (data) {
       
    }, function (data) {
        Feng.error("导出失败!" + data.responseJSON.message + "!");
    });
	ajax.start();
};


/**
 * 查询轮滑进销存储列表
 */
Skate.search = function () {
    var queryData = {};
    queryData['name'] = $("#name").val();
    queryData['type'] = $("#type").val();
    queryData['color'] = $("#color").val();
    queryData['level'] = $("#level").val();
    Skate.table.refresh({query: queryData});
};

Skate.view = function(){
	var ajax = new $ax(Feng.ctxPath + "/skate/pageOffice?", function (data) {
		console.log(data);
		layer.open({
			type: 1,
			title: "123",
			area:["80%","95%"],
			scrollbar: false,
			content: data,
			maxmin:true
			
		});
    }, function (data) {
    	//console.log(data);
    	/*layer.open({
			type: 1,
			title: "123",
			area:["80%","95%"],
			scrollbar: false,
			content: '<script type="text/javascript">' +
				'document.getElementById("PageOfficeCtrl1").SetEnableFileCommand(3, false);' +
				'</script>',
			maxmin:true
			
		});*/
    });
	ajax.set("id","1");
    ajax.start();
}

$(function () {
    var defaultColunms = Skate.initColumn();
    var table = new BSTable(Skate.id, "/skate/list", defaultColunms);
    table.setPaginationType("server");
    Skate.table = table.init();
});
